package org.sanmao.wyj.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.sanmao.wyj.dao.ComplainDao;
import org.sanmao.wyj.domain.Complain;
import org.sanmao.wyj.domain.Order;
import org.sanmao.wyj.service.ComplainService;
import org.sanmao.wyj.service.OrderService;
import org.sanmao.wyj.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.jar.JarEntry;

@Service
public class ComplainServiceImpl extends ServiceImpl<ComplainDao, Complain> implements ComplainService {
    @Autowired
    ComplainDao complainDao;
    @Autowired
    OrderService orderService;

    @Override
    public Boolean addComplain(int oid,Complain complain, HttpServletRequest request) {
        String token = request.getHeader("token");
        int id = JwtUtils.getUserId(token);
        complain.setUid(id);
        Date date = new Date(System.currentTimeMillis());
        complain.setTime(date);
        complain.setState(1);
        complain.setOid(oid);
        int wid = orderService.getById(oid).getWid();
        complain.setWid(wid);
        return complainDao.insert(complain)>0;
    }

    @Override
    public IPage<Complain> findComplainList(int currentPage, int pageSize) {
        IPage<Complain> page = new Page<>(currentPage,pageSize);
        return complainDao.findFullComplain(page);
    }
}
